const units = [
  'Cn25519',
  'CnAEAD',
  'CnAES',
  'CnBase64',
  'CnBerUtils',
  'CnBigNumber',
  'CnBits',
  'CnBLAKE',
  'CnBLAKE2',
  'CnCertificateAuthority',
  'CnChaCha20',
  'CnComplex',
  'CnCRC32',
  'CnDES',
  'CnDFT',
  'CnDSA',
  'CnECC',
  'CnFEC',
  'CnFNV',
  'CnInt128',
  'CnKDF',
  'CnLattice',
  'CnMD5',
  'CnMLDSA',
  'CnMLKEM',
  'CnNative',
  'CnOTP',
  'CnOTS',
  'CnPaillier',
  'CnPDFCrypt',
  'CnPemUtils',
  'CnPoly1305',
  'CnPolynomial',
  'CnPrime',
  'CnRandom',
  'CnRC4',
  'CnRSA',
  'CnSecretSharing',
  'CnSHA1',
  'CnSHA2',
  'CnSHA3',
  'CnSM2',
  'CnSM3',
  'CnSM4',
  'CnSM9',
  'CnTEA',
  'CnVector',
  'CnXXH',
  'CnZUC'
];

function initUnitList() {
  const unitList = document.getElementById('unitList');
  units.forEach(function(unit) {
    const li = document.createElement('li');
    li.className = 'unit-item';
    li.textContent = unit;
    li.onclick = function() { loadUnit(unit); };
    unitList.appendChild(li);
  });
}

function loadUnit(unitName) {
  const frame = document.getElementById('contentFrame');
  frame.src = unitName + '.html';
  
  document.querySelectorAll('.unit-item').forEach(function(item) {
    item.classList.remove('active');
    if (item.textContent === unitName) {
      item.classList.add('active');
    }
  });
}

function initSearch() {
  const searchInput = document.getElementById('searchInput');
  searchInput.addEventListener('input', function() {
    const searchTerm = this.value.toLowerCase();
    const unitItems = document.querySelectorAll('.unit-item');
    
    unitItems.forEach(function(item) {
      const unitName = item.textContent.toLowerCase();
      if (unitName.includes(searchTerm)) {
        item.style.display = 'block';
      } else {
        item.style.display = 'none';
      }
    });
  });
}

document.addEventListener('DOMContentLoaded', function() {
  initUnitList();
  initSearch();
});
